var orderPayDetailApp = angular.module("orderPayDetailApp",[]);
orderPayDetailApp.controller("orderPayDetailController",function($scope){
    //订单价格数据处理，从2处理成2.00格式
	$scope.intToFloat=function(num){
		var obj=num.toString().split(".");
		if(obj.length==1){
			num=num+'.00';
		}
		return num;
		console.log("处理后数据："+num);
	}
    //获取本地存储的订单费用明细信息
    var chargeDetail=localStorage.getItem('chargeDetail');
    console.log(chargeDetail);//2
    if(chargeDetail){
		$scope.order=JSON.parse(chargeDetail);
		//计算充电费和服务费，优惠
		$scope.chargePrice=0;
		$scope.servicePrice=0;
		$scope.discountPrice=0;
		$scope.orderDetails=$scope.order.orderDetails;
		//过滤出充电列表
		$scope.chargeList=[];
		$scope.chargelen=0;
		console.log($scope.orderDetails);
		angular.forEach($scope.orderDetails, function(data,index,array){
			if(array[index].serviceNo=="100002"){
				$scope.chargePrice=parseFloat($scope.chargePrice+array[index].totalPrice);
				$scope.endTime=array[index].endTime.split(" ")[1].substr(0,5);
				$scope.startTime=array[index].startTime.split(" ")[1].substr(0,5);
				$scope.chargeVolume=parseFloat(array[index].totalPrice)/parseFloat($scope.order.stationDetail.chargePriceDescription);
				console.log($scope.chargeVolume);
				if(parseFloat(array[index].totalPrice)%parseFloat($scope.order.stationDetail.chargePriceDescription)!=0){
					$scope.chargeVolume=parseInt($scope.chargeVolume+1);
				}
				console.log($scope.chargeVolume);
				$scope.chargeList[$scope.chargelen]={
					"endTime":$scope.endTime,
					"realTotalPrice":array[index].realTotalPrice,
					"startTime":$scope.startTime,
					"totalPrice":array[index].totalPrice,
					"chargePriceDescription":$scope.order.stationDetail.chargePriceDescription,
					"chargeVolume":$scope.chargeVolume
				};
				$scope.chargelen++;
			}else if(array[index].serviceNo=="100001"){
				console.log(100001);
				$scope.servicePrice=parseFloat($scope.servicePrice+array[index].totalPrice);
			}
			$scope.discountPrice=parseFloat($scope.discountPrice+array[index].totalPrice-array[index].realTotalPrice);
		});
		$scope.chargePrice=$scope.intToFloat($scope.chargePrice);
		$scope.servicePrice=$scope.intToFloat($scope.servicePrice);
		//判断优惠金额是否有值，有则显示，无则隐藏
		$scope.hasDiscount=false;
		if($scope.discountPrice && $scope.discountPrice>0){
			$scope.hasDiscount=true;
			$scope.discountPrice=$scope.intToFloat($scope.discountPrice);
		}
		console.log("充电费计算："+$scope.chargePrice+","+$scope.servicePrice+","+$scope.discountPrice);
		console.log($scope.order);//2
	}
})